/**
 * 
 */
package dt.inlee.system.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import dt.inlee.common.dao.impl.BaseDao;
import dt.inlee.common.exception.FrameworkException;
import dt.inlee.common.util.BaseUtil;
import dt.inlee.domain.SelfDesktopDefend;

/**
 * @功能说明：自己桌面维护数据访问层
 * @作者： xgyin
 * @创建日期： 2010-12-22
 */
@Repository("selfDesktopDefendDao")
public class SelfDesktopDefendDao extends BaseDao {

	/**
	 * 通过用户ID删除用户所有的桌面维护数据
	 * @param loginUserId
	 * @throws FrameworkException
	 */
	public void deleteSelfDesktopDefendsByLoginUserId(String loginUserId) throws FrameworkException {
		StringBuffer sb = new StringBuffer();
		sb.append("DELETE FROM SelfDesktopDefend sdd WHERE sdd.defendUser.id='" + loginUserId + "'");
		Query query = this.hibernateTemplate.getSessionFactory().getCurrentSession().createQuery(sb.toString());
		query.executeUpdate();

	}

	/**
	 * 获取自己主页的桌面模块
	 * @param loginUserId
	 * @return
	 * @throws FrameworkException
	 */
	@SuppressWarnings("unchecked")
	public List<SelfDesktopDefend> findSelfDesktopCenters(int loginUserId) throws FrameworkException {
		Criteria criteria = hibernateTemplate.getSessionFactory().getCurrentSession().createCriteria(
				SelfDesktopDefend.class);
		if (!BaseUtil.isEmpty(loginUserId))
			criteria.add(Restrictions.eq("defendUser.id", loginUserId));
		return criteria.list();
	}
}
